package com.order.entity;

import java.util.*;

import com.bhudy.annotation.PrimaryKey;
import com.bhudy.exception.SysException;
import com.bhudy.exception.SysExceptionCode;

/**
 * @Author 卞洪业
 * @Description ResOrder实体类
 * @Date Wed Feb 19 17:04:47 CST 2020
 */
public class ResOrder {

    @PrimaryKey
    private Long resOrderId;    //Id uuid
    private Long parentId;    //父Id
    private String resOrderName;    //工单标题
    private Long resOrderTypeId;    //关联工单类型Id
    private Long userId;    //当前处理人
    private Long resObjId;    //关联其他对象表的Id
    private String resObjType;    //对象类型
    private Integer priority;    //优先级1低，2中，3高
    private Integer stage;    //当前阶段1新建，2审核，3处理，4审计，5结单
    private Integer orderStatus;    //工单状态码1新建（1新建中，2审核不通过，3接单拒接），2审核（1审核中），3处理（1待接单，2处理中，3审计不通过），4审计（1审计中），5接单（1待结单评价 2关闭）
    private Integer stageSort;    //步骤排序
    private String content;    //需求内容
    private Date completionTime;    //期望完成时间
    private Integer source;    //1：系统 2：用户 3：外部
    private String tags;    //标签
    private String evaluate; // 评价内容
    private Integer evaluateScore; // 评价分数
    private Integer status;    //状态（0正常 1删除 2停用 3冻结）
    private Long createBy;    //创建者
    private Date createDate;    //创建时间
    private Long updateBy;    //更新者
    private Date updateDate;    //更新时间
    private String remark;    //备注信息

    public final static int PRIORITY_LOW = 1; //优先级1低，2中，3高
    public final static int PRIORITY_MIDDLE = 2; //优先级1低，2中，3高
    public final static int PRIORITY_HIGE = 3; //优先级1低，2中，3高

    public final static int SOURCE_SYS = 1; //1：系统 2：用户 3：外部
    public final static int SOURCE_USER = 2; //1：系统 2：用户 3：外部
    public final static int SOURCE_OUTSIDE = 3; //1：系统 2：用户 3：外部

    public enum Stage {
        CREATE(1), //工单状态1新建，2审核，3处理，4审计，5结单
        REVIEW(2), //工单状态1新建，2审核，3处理，4审计，5结单
        HANDLE(3), //工单状态1新建，2审核，3处理，4审计，5结单
        AUDIT(4), //工单状态1新建，2审核，3处理，4审计，5结单
        FINISH(5); //工单状态1新建，2审核，3处理，4审计，5结单

        public int code;

        Stage(int code) {
            this.code = code;
        }
    }

    /**
     * 获取工单状态码
     *
     * @param stage       当前阶段
     * @param orderStatus 工单状态码
     * @return
     */
    public final static int getOrderStatus(Stage stage, int orderStatus) {
        return ResOrder.getOrderStatus(stage.code, orderStatus);
    }

    public final static int getOrderStatus(int stage, int orderStatus) {
        String key = stage + "_" + orderStatus;
        switch (key) {
            case "1_1": //1新建（1新建中，2审核不通过，3接单拒接）
            case "1_2": //1新建（1新建中，2审核不通过，3接单拒接）
            case "1_3": //1新建（1新建中，2审核不通过，3接单拒接）
            case "2_1": //2审核（1审核中）
            case "3_1": //3处理（1待接单，2处理中，3审计不通过）
            case "3_2": //3处理（1待接单，2处理中，3审计不通过）
            case "3_3": //3处理（1待接单，2处理中，3审计不通过）
            case "4_1": //4审计（1审计中）
            case "5_1": //5结单（1待结单评价）
            case "5_2": //5结单（2结单）
            case "5_3": //5结单（3关闭）
                break;
            default:
                throw new SysException(SysExceptionCode.CODE_40032);
        }
        return orderStatus;
    }

    public final static Map<String, String> getOrderStatusMap(int stage, int orderStatus) {
        String key = stage + "_" + orderStatus;
        String label;
        String type;
        switch (key) {
            case "1_1": //1新建（1新建中，2审核不通过，3接单拒接）
                label = "新建中";
                type = "success";
                break;
            case "1_2": //1新建（1新建中，2审核不通过，3接单拒接）
                label = "审核不通过";
                type = "danger";
                break;
            case "1_3": //1新建（1新建中，2审核不通过，3接单拒接）
                label = "接单拒接";
                type = "warning";
                break;
            case "2_1": //2审核（1审核中）
                label = "审核中";
                type = "primary";
                break;
            case "3_1": //3处理（1待接单，2处理中，3审计不通过）
                label = "待接单";
                type = "primary";
                break;
            case "3_2": //3处理（1待接单，2处理中，3审计不通过）
                label = "处理中";
                type = "primary";
                break;
            case "3_3": //3处理（1待接单，2处理中，3审计不通过）
                label = "审计不通过";
                type = "warning";
                break;
            case "4_1": //4审计（1审计中）
                label = "审计中";
                type = "primary";
                break;
            case "5_1": //5结单（1待结单评价）
                label = "待结单";
                type = "primary";
                break;
            case "5_2": //5结单（2结单）
                label = "结单";
                type = "info";
                break;
            case "5_3": //5结单（3关闭）
                label = "关闭";
                type = "info";
                break;
            default:
                throw new SysException(SysExceptionCode.CODE_40032);
        }
        Map<String, String> map = new HashMap<>();
        map.put("label", label);
        map.put("type", type);
        return map;
    }

    public final static List<Map<String, Object>> getOrderButton(int stage, int orderStatus) {
        String key = stage + "_" + orderStatus;
        List<Map<String, Object>> resultList = new ArrayList<>();
        switch (key) {
            case "1_1":
                resultList.add(getButtonMap("发布", "success", "1", "确认发布该工单？", "发布工单", null, 1, 1, true));
                break;
            case "1_2":
            case "1_3":
                resultList.add(getButtonMap("重新发布", "success", "1", "确认发布该工单？", "重新发布工单", null, 1, 1, true));
                break;
            case "2_1":
                resultList.add(getButtonMap("拒绝", "danger", "0", "确认不通过该工单？", "审核不通过,请重新处理", "请填写不通过理由", 2, 2, true));
                resultList.add(getButtonMap("通过", "success", "1", "确认通过该工单?", "审核通过", "请填写通过理由", 2, 1, true));
                break;
            case "3_1":
                resultList.add(getButtonMap("拒绝", "danger", "0", "确认拒绝？", "拒绝该单", "请填写拒单理由", 3, 2, true));
                resultList.add(getButtonMap("接单", "success", "1", "确认接单?", "接单", null, 3, 1, true));
                break;
            case "3_2":
            case "3_3":
                resultList.add(getButtonMap("处理完成", "success", "0", "确认处理完成?", "处理完成", "请填写处理过程", 3, 4, true));
                break;
            case "4_1":
                resultList.add(getButtonMap("不通过", "danger", "0", "确认驳回该工单?", "审计不通过", "请填写不通过理由", 4, 2, true));
                resultList.add(getButtonMap("通过", "success", "1", "确认通过该工单?", "审计通过", "请填写通过理由", 4, 1, true));
                break;
            case "5_1":
                resultList.add(getButtonMap("评价", "primary", "1", "确认对该工单进行评价?", "工单评价", "请填写通过理由", 5, 1, true));
                resultList.add(getButtonMap("重新发布", "success", "1", "确认重新发布该工单?", "重新发布", "请填写重新发布理由", 5, 2, true));
                break;
            case "5_2":
            case "5_3":
                break;
            default:
                throw new SysException(SysExceptionCode.CODE_40032);
        }
        return resultList;
    }

    private static Map<String, Object> getButtonMap(String name, String color, String type, String title,
                                                    String value, String placeholder, int stage, int status, boolean fast) {
        Map<String, Object> map = new HashMap<>();
        map.put("name", name);
        map.put("color", color);
        map.put("type", type);
        Map<String, Object> tapMap = new HashMap<>();
        tapMap.put("title", title);
        tapMap.put("value", value);
        tapMap.put("stage", stage);
        tapMap.put("status", status);
        tapMap.put("fast", fast);
        tapMap.put("placeholder", placeholder);
        map.put("tap", tapMap);
        return map;
    }

    public Long getResOrderId() {
        return resOrderId;
    }

    public void setResOrderId(Long resOrderId) {
        this.resOrderId = resOrderId;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getResOrderName() {
        return resOrderName;
    }

    public void setResOrderName(String resOrderName) {
        this.resOrderName = resOrderName;
    }

    public Long getResOrderTypeId() {
        return resOrderTypeId;
    }

    public void setResOrderTypeId(Long resOrderTypeId) {
        this.resOrderTypeId = resOrderTypeId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getResObjId() {
        return resObjId;
    }

    public void setResObjId(Long resObjId) {
        this.resObjId = resObjId;
    }

    public String getResObjType() {
        return resObjType;
    }

    public void setResObjType(String resObjType) {
        this.resObjType = resObjType;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Integer getStage() {
        return stage;
    }

    public void setStage(Integer stage) {
        this.stage = stage;
    }

    public Integer getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(Integer orderStatus) {
        this.orderStatus = orderStatus;
    }

    public Integer getStageSort() {
        return stageSort;
    }

    public void setStageSort(Integer stageSort) {
        this.stageSort = stageSort;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Date getCompletionTime() {
        return completionTime;
    }

    public void setCompletionTime(Date completionTime) {
        this.completionTime = completionTime;
    }

    public Integer getSource() {
        return source;
    }

    public void setSource(Integer source) {
        this.source = source;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public String getEvaluate() {
        return evaluate;
    }

    public void setEvaluate(String evaluate) {
        this.evaluate = evaluate;
    }

    public Integer getEvaluateScore() {
        return evaluateScore;
    }

    public void setEvaluateScore(Integer evaluateScore) {
        this.evaluateScore = evaluateScore;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Long getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(Long updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

}
